/*
 * inotify-sync - a simple file synchronizer and file system watcher
 * Copyright (C) 2010-2011, inotify-sync developers and inotify-sync contributors
 * Copyright (C) 2010-2011, Cohesion Network Security Studio
 *
 * inotify-sync is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * inotify-sync is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with inotify-sync; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/*
 * FILE:		StdLogger.cpp
 * USAGE:		---
 * DESCRIPTION:		---
 * OPTIONS:		---
 * REQUIREMENTS:	---
 * BUGS:		---
 * NOTES:		---
 * AUTHOR:		LI Yiwei (mail:leeyiw@gmail.com)
 * COMPANY:		---
 * VERSION:		1.0
 * CREATED:		Fri Sep  2 12:28:13 CST 2011
 * REVISION:		---
 */

#include "StdLogger.h"

StdLogger::StdLogger()
{}

StdLogger::~StdLogger()
{}

void
StdLogger::log_create(string abs_path)
{
	log_time();
	printf("inotify-sync : create '%s'\n",abs_path.c_str());
}

void
StdLogger::log_delete(string abs_path)
{
	log_time();
	printf("inotify-sync: delete '%s'\n",abs_path.c_str());
}

void
StdLogger::log_modify(string abs_path)
{
	log_time();
	printf("inotify-sync: modify '%s'\n",abs_path.c_str());
}

void
StdLogger::log_moved_from(string abs_path,uint32_t cookie)
{
	log_time();
	printf("inotify-sync: moved_from '%s'\n",abs_path.c_str());
	printf("inotify-sync: cookie:%d\n",cookie);
}

void
StdLogger::log_moved_to(string abs_path,uint32_t cookie)
{
	log_time();
	printf("inotify-sync: moved_to '%s'\n",abs_path.c_str());
	printf("inotify-sync: cookie:%d\n",cookie);
}

void
StdLogger::log_move_inside(string src_path,string dest_path,uint32_t cookie)
{
	log_time();
	printf("inotify-sync: move_inside:\n");
	printf("inotify-sync: cookie:%d\n",cookie);
	printf("inotify-sync: src '%s'\n",src_path.c_str());
	printf("inotify-sync: dest '%s'\n",dest_path.c_str());
}

void
StdLogger::log_time()
{
	//获取当前精确时间
	timeval time;
	if(gettimeofday(&time,0))
		perror("gettimeofday");
	//产生用户可识别的时间
	struct tm *p_tm=localtime(&(time.tv_sec));
	string year=Conv.conv<string>(p_tm->tm_year+1900);
	string month=Conv.conv<string>(p_tm->tm_mon+1);
	string day=Conv.conv<string>(p_tm->tm_mday);
	string hour=Conv.conv<string>(p_tm->tm_hour);
	string min=Conv.conv<string>(p_tm->tm_min);
	string sec=Conv.conv<string>(p_tm->tm_sec);
	string time_str=string(year+"-"+month+"-"+day+" "+hour+":"+min+":"+sec);
	printf("[%s] ",time_str.c_str());
}
